from django.db import models
from django.utils import timezone


# 基类
class Base(models.Model):
    # 创建时间
    create_time = models.DateTimeField(
        default=timezone.now, null=True)  # now后面加()时间还是固定的

    class Meta:
        abstract = True


class Cate(models.Model):
    name = models.CharField(max_length=500)  # 分类名称
    pid = models.IntegerField()  # 父id

    class Meta:
        db_table = 'cate'

class UserFlow(Base):  # 关注表
    
    uid = models.IntegerField()  # 谁关注的
    gid = models.IntegerField()  # 关注的什么商品
    
    class Meta:
        db_table = 'userflow'

class Comment(Base):  # 用户评论表
    content = models.CharField(max_length=200)  # 评论内容
    uid = models.IntegerField()  # 评论的用户
    gid = models.IntegerField()  # 评论的商品

    class Meta:
        db_table = 'comment'


class Goods(Base):  # 商品表
    name = models.CharField(max_length=200)  # 商品名
    desc = models.CharField(max_length=500)  # 商品简介
    parms = models.CharField(max_length=500)  # 商品规格
    img = models.CharField(max_length=200, null=True)  # 商品头图
    video = models.CharField(max_length=200, null=True)  # 演示视频
    price = models.IntegerField()  # 价格   统一以 分
    flow = models.IntegerField(default=0, null=True)  # 关注数  多对多的关系
    cate_id = models.IntegerField()  # 分类id  一对多的关系

    class Meta:
        db_table = 'goods'


class User(Base):  # 用户表
    username = models.CharField(max_length=128, verbose_name='用户名')
    password = models.CharField(max_length=256, verbose_name='密码')
    img = models.CharField(max_length=256, verbose_name='图片名')
    image = models.CharField(max_length=256, verbose_name='视频地址', null=True)
    # 类别 0普通用户 1 超级管理员
    type = models.IntegerField(default=0, null=True)

    class Meta:
        db_table = 'User'


class Pics(Base):  # 幻灯片表
    title = models.CharField(max_length=256)  # 图片内容
    link = models.CharField(max_length=256)  # 链接
    image = models.CharField(max_length=256)  # 图片链接

    class Meta:
        db_table = 'pics'
